#include "Sprite.h"
#include "BaseD3D.h"
#include "GlobalUse.h"

VSprite::VSprite(void)
{
	
}

VSprite::VSprite(CString strSpriteName)
{
	VBaseD3D* baseD3D = gfGetD3DBase();
	//Create sprite
	D3DXCreateTextureFromFileEx(baseD3D->d3ddev,		// the device pointer
                            strSpriteName,				// the new file name
                            D3DX_DEFAULT,				// default width
                            D3DX_DEFAULT,				// default height
                            D3DX_DEFAULT,				// no mip mapping
                            NULL,						// regular usage
                            D3DFMT_A8R8G8B8,			// 32-bit pixels with alpha
                            D3DPOOL_MANAGED,			// typical memory handling
                            D3DX_DEFAULT,				// no filtering
                            D3DX_DEFAULT,				// no mip filtering
                            D3DCOLOR_XRGB(255, 0, 255),	// the hot-pink color key
                            NULL,						// no image info struct
                            NULL,						// not using 256 colors
                            &m_sprite);					// load to sprite
	m_v3position = new VVector3(0.0f,0.0f,0.0f);
	m_v3anchor = new VVector3(0.0f, 0.0f, 0.0f);
}

VSprite::~VSprite(void)
{
	delete m_v3position;
	m_v3position = NULL;
	delete m_v3anchor;
	m_v3anchor = NULL;
}

void VSprite::Draw() {
	VBaseD3D* baseD3D = gfGetD3DBase();
    // draw the sprite
    baseD3D->d3dspt->Draw(m_sprite, 
		NULL, 
		&m_v3anchor->GetPosition(), 
		&m_v3position->GetPosition(), 
		D3DCOLOR_XRGB(255, 255, 255));
}

void VSprite::Release() {
	m_sprite->Release();
}

void VSprite::SetPosition(float fX,float fY)
{
	m_v3position->m_fX = fX;
	m_v3position->m_fY = fY;
}